package com.leetcode.LC;

import java.util.Arrays;

public class LC1413 {
    public int minStartValue(int[] nums) {
        int[] a = nums.clone();
        int min = Integer.MAX_VALUE, sum = 0;
        boolean f = false;
        Arrays.sort(a);
        if (a[0] >= 0) {
            return 1;
        } else {
            for (int num : nums) {
                sum += num;
                if (sum < 0) {
                    min = Math.min(min, sum);
                    f = true;
                }
            }
        }
        if (f) {
            return Math.abs(min) + 1;
        } else {
            return 1;
        }
    }

    public static void main(String[] args) {
        System.out.println(new LC1413().minStartValue(new int[]{-3, 2, -3, 4, 2}));
    }
}
